package com.sanery.controller.ajax;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sanery.service.UserService;
import com.sanery.service.impl.UserServiceImpl;

@WebServlet("/reg/getprovice")
public class GetProvince extends HttpServlet {
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		UserService u = new UserServiceImpl();
		List<String> list = u.getProvince();
		String json = "";
		for (String sc : list) {
			json = json + "\"" + sc + "\",";
		}
		if (json.length() > 0) {
			json = json.substring(0, json.length() - 1);
		}

		// 返回数据
		response.setContentType("application/json;charset=UTF-8");
		PrintWriter out = response.getWriter(); // 输出文字
		try {
			out.print("{\"province\":[" + json + "]}");
		} finally {
			out.flush();
			out.close();
		}
	}

}
